package com.zer0.tga.entity.livingentity.mob;

import com.zer0.tga.art.ArtArchive;
import com.zer0.tga.art.Bitmap;
import com.zer0.tga.entity.Entity;
import com.zer0.tga.entity.livingentity.Teemo;
import com.zer0.tga.entity.livingentity.flyingentity.TeemoDart;
import com.zer0.tga.math.Direction;
import com.zer0.tga.math.RandNum;

public class BoomerangBlade extends Mob {
	
	

	private int rn;
	
	public void init()
	{
		//System.out.println("init");
		unitType = UnitType.ENEMY;
		health = maxHealth = 10;
		movementSpeed = 3.0;
		rn = RandNum.getRandNum(1, 4);
	}

	@Override
	public void action() {

		if(rn==1)
			move(movementSpeed, movementSpeed);
		else if(rn==2)
			move(movementSpeed, -movementSpeed);
		else if(rn==3)
			move(-movementSpeed, -movementSpeed);
		else if(rn==4)
			move(-movementSpeed, movementSpeed);
		
	}

	@Override
	public Bitmap getArt() {
		// TODO Auto-generated method stub
		return ArtArchive.boomerangblade[(livingTime/2)%3][0];
	}
	

	public boolean collision(Entity entity, Direction dir) 
    {
		if(entity instanceof TeemoDart)
		{
			hurt(((TeemoDart) entity).damage);
			entity.removed = true;
			return true;
		}
		else if (entity instanceof Teemo)
		{
			//System.out.println("Collision!");
			((Teemo) entity).hurt(damage);
			changeDir(dir);
		}
		else if(entity == null || entity instanceof BoomerangBlade)
		{
			changeDir(dir);
		}

		return false;
    }
	
	private void changeDir(Direction dir)
	{
		if(dir == Direction.NORTH || dir == Direction.SOUTH)
		{		
			if(rn == 1) rn = 2;
			else if(rn == 2) rn = 1;
			else if(rn == 3) rn = 4;
			else if(rn == 4) rn = 3;	
		}
		else if(dir == Direction.WEST || dir == Direction.EAST)
		{
			if(rn == 1) rn = 4;
			else if(rn == 2) rn = 3;
			else if(rn == 3) rn = 2;
			else if(rn == 4) rn = 1;	
		}
	}

	@Override
	public boolean blocks(Entity e) {
		
		if(e instanceof BoomerangBlade)
			return true;
		return super.blocks(e);
	}
}